﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wait-send.aspx.cs" Inherits="famails.BackEnd.page.wait_send" MasterPageFile="~/Master.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <!-- start update panel-->
<style>
    #txtFrom {
        height:34px !important;
    }
    #txtTo {
        height:34px !important;
    }
    #contentjqxgrid {
        width:100% !important;
    }
    #pagerjqxgrid {
        width:100% !important;
    }
    #contentjqxgrid_error{
        width:100% !important;
    }
    #pagerjqxgrid_error{
        width:100% !important;
    }
</style>

<div style="width:100%;padding:10px;">
<!--start content 01-->
    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="border:1px solid #333;margin-bottom:10px;padding:0px;">
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:10px 20px;background:#000;color:#fff;font-size:18px;font-weight:bold;position:relative;">   
                    Danh sách nội dung gửi
                </div>
                <asp:Panel ID="pnError" runat="server" Visible="false">
                    <div class="error-box round">
                        <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
                    </div>
                </asp:Panel>
                <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                    <div class="confirmation-box round">
                        <asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label>
                    </div>
                </asp:Panel>
                <asp:Panel ID="pnSearch" runat="server">
                    
        <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:0px;">
                <div class="col-md-2 col-lg-2 col-sm-4 col-xs-4" style="padding:5px;padding-left:0px;">
                    <label for="simple-input" style="line-height:30px;font-weight: bolder;padding-left:10px ;text-transform: none">Từ ngày</label>
                </div>
                
                <div class="col-md-2 col-lg-2 col-sm-8 col-xs-8" style="padding:5px;padding-left:0px;">
                    <div id="txtFrom"></div>
                </div>
                <div class="col-md-2 col-lg-2 col-sm-4 col-xs-4" style="padding:5px;padding-left:0px;">
                    <label for="simple-input" style="line-height:30px;padding-left:10px ;font-weight: bolder; text-transform: none">Đến ngày</label>
                </div>
                <div class="col-md-2 col-lg-2 col-sm-8 col-xs-8" style="height:34px;padding:5px;padding-left:0px;">
                     <div id="txtTo"></div>
                </div>
                <div class="col-sm-12 col-xs-12 col-md-4 col-lg-4 ">
                    <div class="col-md-6 col-lg-6 col-sm-6 col-xs-6" style="padding:5px;padding-left:0px;">
<%--                        <button id="btnSearch" style="padding:7px 13px;text-align:center;width:100%;background:#333;color:#fff;font-weight:bold;border-radius:0px;" class="btn"><span class="fa fa-desktop"></span> Lọc dữ liệu</button>--%>
                                <asp:Button ID="btnSearch" style="padding:6px 13px;text-align:center;width:100%;background:#333;color:#fff;font-weight:bold;border-radius:0px;" class="btn">
                                    <span style="margin-right:10px;" class="fa fa-desktop"></span> Lọc dữ liệu
                                </asp:Button>
                    </div>
                    <div class="col-md-6 col-lg-6 col-sm-6 col-xs-6" style="padding:5px;padding-left:0px;padding-right:0px;">
                                <asp:Button ID="btnExportExcel" style="padding:6px 13px;text-align:center;width:100%;background:#333;color:#fff;font-weight:bold;border-radius:0px;" class="btn">
                                    <span style="margin-right:10px;" class="fa fa-mail-forward"></span> Xuất dữ liệu
                                </asp:Button>
                    </div>
                </div>
                <div class="col-sm-12 col-xs-12 col-md-12 col-lg-12 " hidden id="FilterTable" style="width:100%;"></div>

                <div class="col-sm-12 col-xs-12 col-md-12 col-lg-12" style="padding:0px;">
                    <div id='jqxWidget' style="width:100% !important;font-size: 13px; font-family: Verdana; float: left;">
                    <div id="jqxgrid" style="width:100% !important;">
                    </div>

                    <div id="popupWindow">
                        <div>
                            Xóa Broadcasting
                        </div>
                        <div style="overflow: hidden;">
                            <p>
                                Bạn có chắc là muốn xóa Broadcasting này không?
                            </p>
                            <button id="del">
                                Yes</button>
                            <button id="cancel">
                                No</button>
                        </div>
                    </div>
                </div>
                </div>
                </asp:Panel>
        </div>
    </div>
</div>
    <!-- end update panel-->
    <script type="text/javascript">

        jQuery(function ($) {

            $("#txtFrom").jqxDateTimeInput({ width: '150px', height: '25px' });
            $("#txtTo").jqxDateTimeInput({ width: '150px', height: '25px' });

            $("#btnExportExcel").click(function () {
                $("#jqxgrid").jqxGrid('exportdata', 'xls', 'registeremaillist');
            });
            var cellsrenderer = function (row, column, value) {
                var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "Id");
                //alert(name);
                return '<a style="margin: 4px;color:#333;" href="reportSend.aspx?id=' + id + '">Xem kết quả</a>';
            }
            $("#btnSearch").click(function () {
                $("#jqxgrid").jqxGrid('showloadelement');
                var postValue = "{from:'" + $('#txtFrom').jqxDateTimeInput('getText') + "',to:'" + $('#txtTo').jqxDateTimeInput('getText') + "'}";
                //alert(postValue);
                $.ajax({
                    type: "POST",
                    url: "wait-send.aspx/search",
                    data: postValue,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'Id', type: 'int' },
                        { name: 'Name', type: 'int' },
                        { name: 'Subject', type: 'string' },
                        { name: 'GroupName', type: 'string' },
                        { name: 'StartDate', type: 'date' },
                        { name: 'EndDate', type: 'date' },
                        { name: 'TotalSend', type: 'decimal' },
                        { name: 'Sent', type: 'decimal' }
                    ],
                    id: 'Id',
                    localdata: data,
                    pager: function (pagenum, pagesize, oldpagenum) {
                    }
                };
                        var dataAdapter = new $.jqx.dataAdapter(source);
                        $("#jqxgrid").jqxGrid(
                        {
                            width: $('#jqxWidget').width(),
                            source: dataAdapter,
                            selectionmode: 'multiplerowsextended',
                            sortable: true,
                            pageable: true,
                            autoheight: true,
                            enabletooltips: true,
                            columnsresize: true,
                            //pagermode: 'simple',
                            columns: [
                                { text: 'Danh sách nội dung', datafield: 'Subject'},
                                { text: 'Nhóm email', datafield: 'GroupName' },
                                { text: 'Email gửi', datafield: 'Name', title: true },
                                { text: 'Thời gian bắt đầu', datafield: 'StartDate', cellsalign: 'center', cellsformat: 'dd/MM/yyyy HH:mm:ss', width: 150 },
                                { text: 'Thời gian kết thúc', datafield: 'EndDate', cellsalign: 'center', cellsformat: 'dd/MM/yyyy HH:mm:ss', width: 150 },
                                { text: 'Kết quả', cellsrenderer: cellsrenderer, width: 120 },
                                {
                                    text: 'Xóa', datafield: 'Delete', columntype: 'button', cellsrenderer: function () {
                                        return "Xóa";
                                    }, buttonclick: function (row) {
                                        // open the popup window when the user clicks a button.
                                        id = $("#jqxgrid").jqxGrid('getrowid', row);
                                        var offset = $("#jqxgrid").offset();
                                        $("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
                                        // show the popup window.
                                        $("#popupWindow").jqxWindow('show');
                                    }
                                }
                            ]
                        });

                    }
                });
            });
            $("#popupWindow").jqxWindow({ width: 250, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.01 });
            $("#del").jqxButton({ theme: theme });
            $("#cancel").jqxButton({ theme: theme });
            $("#del").click(function () {
                $.ajax({
                    type: "POST",
                    url: "wait-send.aspx/Delete",
                    data: "{id:" + id + "}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $('#jqxgrid').jqxGrid('deleterow', id);
                        $("#popupWindow").jqxWindow('hide');
                        $('#btnSearch').trigger('click');
                    },
                    error: function (request, status, error) {
                        alert('Broadcating đã được gửi. Bạn không được phép xóa!');
                        $("#popupWindow").jqxWindow('hide');
                    }
                });
            });
            $("#cancel").click(function () {
                $("#popupWindow").jqxWindow('hide');
            });
        $('#btnSearch').trigger('click');
        });

    </script>

</asp:Content>
